package conversions

import (
	"gvm/instructions/base"
	"gvm/rtda"
	"reflect"
	"strings"
)

type I2X[X interface{}] struct{ base.NoOperandsInstruction }

func (self *I2X[X]) Execute(jFrame *rtda.JFrame) {
	stack := jFrame.OperandStack()
	e := reflect.TypeOf(self).Elem().String()
	etype := strings.ReplaceAll(strings.Split(e, "[")[1], "]", "")
	switch etype {
	case "int64":
		stack.PushLong(int64(stack.PopInt()))
		break
	case "int32":
		stack.PushInt(stack.PopInt())
		break
	case "float32":
		stack.PushFloat(float32(stack.PopInt()))
		break
	case "float64":
		stack.PushDouble(float64(stack.PopInt()))
		break
	}
}

type I2D struct {
	I2X[float64]
}

type I2F struct {
	I2X[float32]
}

type I2L struct {
	I2X[int64]
}

type I2B struct {
	I2X[int32]
}

type I2S struct {
	I2X[int32]
}

type I2C struct {
	I2X[int32]
}
